package cate.game.world.beta;

import cate.game.GameBody;
import cate.game.framework.ModuleMan;
import cp.solution.manage.PrimaryClient;
import lombok.extern.slf4j.Slf4j;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Slf4j
public class BetaPayManager extends ModuleMan {

    private static Set<String> openIdSet;
    public static synchronized void loadOpenIdSet(PrimaryClient pc) {
        if(openIdSet == null) {
            openIdSet = new HashSet<>();
            try {
                List<String> allOpenIds = pc.world.beta.findAllOpenIds();
                for(String openId : allOpenIds) {
                    openIdSet.add(openId);
                }
            } catch (Exception e) {
                log.error("", e);
            }
        }
    }

    @Override
    public void initIndependent(GameBody game) throws Exception {
        super.initIndependent(game);
        loadOpenIdSet(game.apis());
    }

    @Override
    public void initDependent() throws Exception {

    }

    @Override
    public void shutdown() {
        super.shutdown();
    }

    public void tick() {

    }

    /** 是否通过openId就能直接排除去world-server查询的必要性 */
    public boolean skipRefund(String openId) {
        if(openIdSet == null || openIdSet.isEmpty()) {
            return false;
        }
        return !openIdSet.contains(openId);
    }

}
